package user_mapping

import (
	"context"

	"algo-sdk-go/common/tools"
	"algo-sdk-go/project/matchmaking/matchMaking-api/internal/logic/user_profile"
	"algo-sdk-go/project/matchmaking/matchMaking-api/internal/svc"
	"algo-sdk-go/project/matchmaking/matchMaking-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserMappingLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserMappingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserMappingLogic {
	return &UserMappingLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserMappingLogic) UserMapping(req *types.UserMappingRequest) (resp *types.UserMappingResponse, err error) {
	userProfileList, err := l.svcCtx.MatchService.Match(l.ctx, req.UserNum)
	if err != nil {
		return nil, err
	}

	resp = &types.UserMappingResponse{
		Data: types.UserMappingData{
			MatchedUserList: tools.Cast(userProfileList, user_profile.CastAllDataDto2Type),
		},
	}
	return
}
